<template>
  <div>
    <ZgEdit
      ref="dialog"
      :view="view"
      :columns="columns"
      :formulas="formulas"
      :inputClick="inputClick"
      validUrl=""
      saveUrl=""
      @ok="$emit('ok')"
    >
    </ZgEdit>
  </div>
</template>
<script>
const selectData = [
  { value: '1', label: '选项1' },
  { value: '2', label: '选项2' },
  { value: '3', label: '选线3' }
]
export default {
  data () {
    return {
      type: 'add',
      obj: null,
      view: { width: '50%', top: '5%', title: '新增' },
      columns: [
        {
          name: '企业类型',
          code: 'political',
          compType: '下拉选择',
          isNeed: true,
          offset: 0,
          span: 12,
          defaultVal: '',
          extra: { 字典类型: 'political' }
        },
        {
          name: '企业名称',
          code: 'select',
          compType: '下拉选择',
          isNeed: true,
          offset: 0,
          span: 12,
          defaultVal: '1',
          extra: { 下拉选项: selectData, placeholder: '请选择' }
        },
        {
          name: '企业用户',
          code: 'select',
          compType: '下拉选择',
          isNeed: true,
          offset: 0,
          span: 12,
          defaultVal: '1',
          extra: { 下拉选项: selectData, placeholder: '请选择' }
        },
        {
          name: '联系电话',
          maxLength: 11,
          code: 'name3',
          compType: '单行文本',
          isNeed: true,
          offset: 0,
          span: 12,
          defaultVal: '',
          regex: '',
          errorMsg: '',
          extra: { placeholder: '请输入' }
        },
        {
          name: '通知类型',
          code: 'select',
          compType: '下拉选择',
          isNeed: true,
          offset: 0,
          span: 12,
          defaultVal: '1',
          extra: { 下拉选项: selectData, placeholder: '请选择' }
        }
      ],
      formulas: [
        { triggerMode: '初始化时', name: '公式1', content: 'console.log("init");' },
        { triggerMode: '数据变化时', name: '公式2', content: 'console.log("update");' },
        { triggerMode: '提交时', name: '公式3', content: 'console.log("submit");' }
      ]
    }
  },
  methods: {
    open (type, json) {
      this.type = type
      let title
      if (type === 'add') {
        title = '新增'
      } else if (type === 'edit') {
        title = '编辑'
      } else {
        title = '详情'
      }
      this.view = { width: '50%', top: '5%', title: title }
      this.obj = Object.assign({}, this.obj, json || {})
      this.$refs.dialog.open()
    },
    inputClick (t) {
      alert(JSON.stringify(t))
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
